package com.lgy.controller;

import com.lgy.dto.OrderDTO;
import com.lgy.message.StreamInput;
import com.lgy.message.StreamOutput;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.Output;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

//@RestController
//@EnableBinding(Source.class)
//public class SendMessageController {
//
//    /**
//     * 使用系统自带的
//     */
//    @Autowired
//    @Output(Source.OUTPUT)
//    public MessageChannel messageChannel;
//
//    @GetMapping("/sendMessage")
//    public void process() {
//        messageChannel.send(MessageBuilder.withPayload("时间: " + new Date()).build());
//    }
//
//}

@RestController
@EnableBinding(StreamOutput.class)
public class SendMessageController {

    /**
     * 自定义的
     */
    @Autowired
    public StreamInput streamInput;

//    @GetMapping("/sendMessage")
//    public void process() {
//        streamInput.input().send(MessageBuilder.withPayload("时间: " + new Date()).build());
//    }

    @GetMapping("/sendMessage")
    public void process() {
        OrderDTO orderDTO = new OrderDTO();
        orderDTO.setBuyerAddress("地址");
        orderDTO.setBuyerName("名称");
        streamInput.input().send(MessageBuilder.withPayload(orderDTO).build());
    }
}
